jQuery(document).ready(function() {

    // Override default error message
    jQuery.validator.messages.required = "";

    // Override generation of error label
    $("#post").validate({
        errorPlacement: function(error, element) {
            /*element.parent("div").addClass('error');*/
        },
        debug: true,
        rules: {
            width: "required",
            height: "required"
        },
        submitHandler: function(form) {

            $('input[type=submit]', '#post').attr('disabled', 'disabled');

            var form = $("#post");
            var form_data = form.serialize();

            $.ajax({
                url: base_url + 'cmssettings/submit_post',
                dataType: 'json',
                type: "POST",
                data: form_data,
                success: function(data, textStatus, xhr) {

                    if (data.action == true) {

                        jQuery('#message').show();

                        // REDIRECT
                        function promo_show() {
                            window.location.href = base_url + 'cmssettings/view_all_thimbnail_size?post_type=thumbnails';
                        }
                        window.setTimeout(function() {
                            promo_show();
                        }, 1001);

                    } else {

                        $('#post').removeAttr('disabled');
                        alert(data.msg)
                    }
                },
                error: function(xhr, textStatus, errorThrown) {
            
            alert(xhr)
            alert(textStatus)
            alert(errorThrown)
            
                    alert('Error ocured...\n Server not found.');
                    $('input[type=submit]', '#post').removeAttr('disabled');
                }
            });

        },
    });

    $('input[type=submit]', '#post').removeAttr('disabled');


});